/* 
 * @(#)WCPromptDialog.java    Created on 2015-3-24
 * Copyright (c) 2015 ZDSoft Networks, Inc. All rights reserved.
 * $Id$
 */
package com.xuan.wcdialog;


import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;

/**
 * 可输入文字的自定义Dialog
 * 
 * @author xuan
 * @version $Revision: 1.0 $, $Date: 2015-3-24 下午4:47:13 $
 */
public class WCPromptDialog extends WCDialog {
    public WCPromptDialog(Context context) {
        super(context);
    }

    public static class Builder {
        private Activity activity;
        private String message;
        private String title;
        private String leftBtnText;
        private String rightBtnText;
        private PromptDialogListener leftBtnListener;
        private PromptDialogListener rightBtnListener;

        public Builder(Context context) {
            activity = (Activity) context;
        }

        public Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        public Builder setMessage(String message) {
            this.message = message;
            return this;
        }
        
        public Builder setLeftBtnText(String leftBtnText) {
            this.leftBtnText = leftBtnText;
            return this;
        }
        
        public Builder setRightBtnText(String rightBtnText) {
            this.rightBtnText = rightBtnText;
            return this;
        }
        
        public Builder setOnLeftBtnListener(PromptDialogListener leftBtnListener) {
            this.leftBtnListener = leftBtnListener;
            return this;
        }
        
        public Builder setOnRightBtnListener(PromptDialogListener rightBtnListener) {
            this.rightBtnListener = rightBtnListener;
            return this;
        }

        public WCPromptDialog create() {
            final WCPromptDialog dialog = new WCPromptDialog(activity);
            dialog.inputEdit.setVisibility(View.VISIBLE);

            if (!TextUtils.isEmpty(title)) {
                dialog.titleTextView.setText(title);
            }

            if (!TextUtils.isEmpty(message)) {
                dialog.messageTextView.setText(message);
            }
            
            if(!TextUtils.isEmpty(leftBtnText)){
            	dialog.leftBtn.setText(leftBtnText);
            }
            
            dialog.leftBtn.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					dialog.dismiss();
					if(null != leftBtnListener){
						leftBtnListener.onClick(view, dialog.inputEdit.getText().toString());
					}
				}
			});
            
            if(!TextUtils.isEmpty(rightBtnText)){
            	dialog.rightBtn.setText(rightBtnText);
            }
            
            dialog.rightBtn.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					dialog.dismiss();
					if(null != rightBtnListener){
						rightBtnListener.onClick(view, dialog.inputEdit.getText().toString());
					}
				}
			});

            return dialog;
        }
    }
    
    /**
     * 点击监听
     * 
     * @author xuan
     */
    public interface PromptDialogListener{
    	void onClick(View view, String inputText);
    }

}
